export interface ICanvasOption {
    /**
     * Fill color for shapes and text. eg: '#67C23A'
     */
    fillStyle?: string;
    /**
     * Font style for text. eg: '16px sans-serif'
     */
    font?: string;
    /**
     * Line width for shapes. Default is 1.
     */
    lineWidth?: number;
    /**
     * Stroke color for shapes and text. eg: '#67C23A'
     */
    strokeStyle?: string;
    /**
     * Line cap style for shapes. eg: 'round', 'butt', 'square'
     */
    lineCap?: CanvasLineCap;
    /**
     * Line join style for shapes. eg: 'round', 'bevel', 'miter'
     */
    lineJoin?: CanvasLineJoin;
}
export interface IPosition {
    x: number;
    y: number;
}
export interface IDrawRect extends IPosition {
    w: number;
    h: number;
    option?: ICanvasOption;
}
export interface IChar {
    c: string;
    x: number;
    y: number; // 字符y坐标
    ry: number; // 矩形的相对y坐标
    w: number;
    hAscent: number;
    hDescent: number;
    fontSize: number; // 字体大小
    fontFamily: string; // 字体族
    color: string;
}
export interface IBaseChar {
    c: string; // 字符
    fontSize: number; // 字体大小
    fontFamily: string; // 字体族
    color: string; // 字体颜色
}
export interface ILineChars {
    chars: IChar[];
    w: number; // 当前行的宽度 累加
    h: number; // 当前行的高度=chars.max(h)
    x: number; // 当前行的起始x坐标
    y: number; // 当前行的起始y坐标
    maxHAscent: number;
    maxHDescent: number; // 当前行的最大上边距和下边距高度
}

export const ARROW_UP = 'ArrowUp';
export const ARROW_DOWN = 'ArrowDown';
export const ARROW_LEFT = 'ArrowLeft';
export const ARROW_RIGHT = 'ArrowRight';
export const ENTER = 'Enter';
export const BACKSPACE = 'Backspace';
export const DELETE = 'Delete';
export const ESCAPE = 'Escape';
export const ARROW_KEY_SET = new Set([
    ARROW_UP,
    ARROW_DOWN,
    ARROW_LEFT,
    ARROW_RIGHT,
]);
export type TArrowKey = typeof ARROW_UP | typeof ARROW_DOWN | typeof ARROW_LEFT | typeof ARROW_RIGHT;
export interface IData {
    id: string;
    w: number;
    h: number;
    x: number;
    y: number;
    // maxWidth?: number; // 若有该值会限制每行的文本长度数量
    baseChars: IBaseChar[]; // 整个文本的字符信息
    lineChars: ILineChars[]; // 每行的字符信息
    parentId: string;
    bg: string;
    color: string; // 字体颜色，优先度低于字符的颜色
    children: {
        ids: string[];
        mh: number;
        mw: number;
    }
}

export const SHOW_CURSOR_COLOR = 'black';
export const HIDE_CURSOR_COLOR = 'white';
export type TCursorColor = typeof SHOW_CURSOR_COLOR | typeof HIDE_CURSOR_COLOR;
export interface ICursor {
    x: number; // 光标的x坐标
    y: number; // 光标的y坐标
    w: number; // 光标的宽度 固定为 2px
    h: number; // 光标的高度 无则不显示，有则为左右节点的最大高度
    startIndex: number;
    startLocation: TCursorLocation;
    renderStartIndex: number;
    endIndex: number; // 光标所在的字符范围
    endLocation: TCursorLocation;
    renderEndIndex: number;
    color: TCursorColor; // 光标颜色
    interval: number, // 光标闪烁的时间间隔
    setIntervalNum: number;
}

export interface IRect extends IPosition {
    w: number;
    h: number;
}

export interface IFontHeight {
    h: number;
    hAscent: number;
    hDescent: number;
}

export interface ISelectZmind {
    index: number;
}

export type TCursorLocation = 'prev' | 'mid' | 'after' | ''; // prev mid after
export interface ICursorSelectPos {
    index: number;
    location: TCursorLocation
}

export type TCursor = 'default' | 'pointer';